package com.martin.lib_base.base

import android.os.Bundle
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.LinearLayoutManager
import com.martin.lib_base.R
import com.martin.lib_base.common.CommonAdapter
import com.martin.lib_base.databinding.ActivityBaseListBinding
import com.martin.lib_base.interfaces.IGetData
import com.martin.lib_base.model.PageModel

/**
 * @author：Houge
 * @date：2022/12/5
 * @desc：基础列表Activity
 */
abstract class BaseListActivity<VM : BaseListViewModel>
    : BaseActivity<ActivityBaseListBinding, VM>() {

    override fun layoutId() = R.layout.activity_base_list

    override fun initOnCreate(savedInstanceState: Bundle?) {
        binding.topBar.setTitle(getTopTitle())
        binding.rv.adapter = CommonAdapter(requireContext(), getViewHolders())
        binding.rv.layoutManager = getLayoutManager()

        viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)

        viewModel.getData()
    }

    /**
     * 获取列表item视图持有者列表
     */
    abstract fun getViewHolders(): List<Class<out BaseViewHolder<*, out ViewDataBinding>>>

    /**
     * 获取布局管理者
     */
    open fun getLayoutManager() = LinearLayoutManager(requireContext())

    /**
     * 获取标题
     */
    abstract fun getTopTitle(): String
}